<?php
        
if (!defined('HIDDEN'))  define('HIDDEN', BaseRecognizer::$HIDDEN);

class ExpParser extends AntlrParser {
    
    public static $tokenNames = array("<invalid>", "<EOR>", "<DOWN>", "<UP>", "Number", "WS", "'+'", "'-'", "'*'", "'/'", "'('", "')'");
    public $WS = 5;
    public $Number = 4;
    public $T__11 = 11;
    public $T__10 = 10;
    public $EOF = -1;
    public $T__9 = 9;
    public $T__8 = 8;
    public $T__7 = 7;
    public $T__6 = 6;
    static $FOLLOW_additionExp_in_compute32;
    static $FOLLOW_multiplyExp_in_additionExp60;
    static $FOLLOW_6_in_additionExp82;
    static $FOLLOW_multiplyExp_in_additionExp86;
    static $FOLLOW_7_in_additionExp102;
    static $FOLLOW_multiplyExp_in_additionExp106;
    static $FOLLOW_atomExp_in_multiplyExp147;
    static $FOLLOW_8_in_multiplyExp168;
    static $FOLLOW_atomExp_in_multiplyExp172;
    static $FOLLOW_9_in_multiplyExp188;
    static $FOLLOW_atomExp_in_multiplyExp192;
    static $FOLLOW_Number_in_atomExp233;
    static $FOLLOW_10_in_atomExp261;
    static $FOLLOW_additionExp_in_atomExp265;
    static $FOLLOW_11_in_atomExp267;
    
    public function __construct($input, $state = null) {
        
        if ($state == null) {
            $state = new RecognizerSharedState();
        }
        parent::__construct($input, $state);
    }
    
    public function getTokenNames() {
        
        return ExpParser::$tokenNames;
    }
    
    public function getGrammarFileName() {
        
        return "Exp.g";
    }
    
    public function compute() {
        
        $value = null;
        $exp   = null;
        
        try { 
            $this->pushFollow(self::$FOLLOW_additionExp_in_compute32);
            $exp = $this->additionExp();
            $this->state->_fsp--;
            $value = $exp;
            
        } catch (RecognitionException $re) {
            $this->reportError($re);
            $this->recover($this->input, $re);
        } catch (Exception $e) {
            throw $e;
        }
        
        return $value;
    }
    
    public function additionExp() {
        
        $value = null;
        $m1    = null;
        $m2    = null;
        
        try { 
            $this->pushFollow(self::$FOLLOW_multiplyExp_in_additionExp60);
            $m1 = $this->multiplyExp();
            $this->state->_fsp--;
            $value = $m1;
            do {
                $alt1  = 3;
                $LA1_0 = $this->input->LA(1);
                if (($LA1_0 == $this->getToken('6'))) {
                    $alt1 = 1;
                } else if (($LA1_0 == $this->getToken('7'))) {
                    $alt1 = 2;
                }
                
                switch ($alt1) {
                    case 1: {
                        $this->match($this->input, $this->getToken('6'), self::$FOLLOW_6_in_additionExp82);
                        $this->pushFollow(self::$FOLLOW_multiplyExp_in_additionExp86);
                        $m2 = $this->multiplyExp();
                        $this->state->_fsp--;
                        $value += $m2;
                    }
                        break;
                    case 2: {
                        $this->match($this->input, $this->getToken('7'), self::$FOLLOW_7_in_additionExp102);
                        $this->pushFollow(self::$FOLLOW_multiplyExp_in_additionExp106);
                        $m2 = $this->multiplyExp();
                        $this->state->_fsp--;
                        $value -= $m2;
                    }
                        break;
                    default:
                        break 2;
                }
            } while (true);
            
        } catch (RecognitionException $re) {
            $this->reportError($re);
            $this->recover($this->input, $re);
        } catch (Exception $e) {
            throw $e;
        }
        
        return $value;
    }

    public function multiplyExp() {
        
        $value = null;
        $a1    = null;
        $a2    = null;
        try { {
                $this->pushFollow(self::$FOLLOW_atomExp_in_multiplyExp147);
                $a1 = $this->atomExp();
                $this->state->_fsp--;
                $value = $a1;
                do {
                    $alt2  = 3;
                    $LA2_0 = $this->input->LA(1);
                    if (($LA2_0 == $this->getToken('8'))) {
                        $alt2 = 1;
                    } else if (($LA2_0 == $this->getToken('9'))) {
                        $alt2 = 2;
                    }
                    switch ($alt2) {
                        case 1: {
                            $this->match($this->input, $this->getToken('8'), self::$FOLLOW_8_in_multiplyExp168);
                            $this->pushFollow(self::$FOLLOW_atomExp_in_multiplyExp172);
                            $a2 = $this->atomExp();
                            $this->state->_fsp--;
                            $value *= $a2;
                        }
                            break;
                        case 2: {
                            $this->match($this->input, $this->getToken('9'), self::$FOLLOW_9_in_multiplyExp188);
                            $this->pushFollow(self::$FOLLOW_atomExp_in_multiplyExp192);
                            $a2 = $this->atomExp();
                            $this->state->_fsp--;
                            $value /= $a2;
                        }
                            break;
                        default:
                            break 2;
                    }
                } while (true);
            }
        }  catch (RecognitionException $re) {
            $this->reportError($re);
            $this->recover($this->input, $re);
        } catch (Exception $e) {
            throw $e;
        }
        
        return $value;
    }

    public function atomExp() {
        
        $value = null;
        $n     = null;
        $exp   = null;
        
        try {
            $alt3  = 2;
            $LA3_0 = $this->input->LA(1);
            if (($LA3_0 == $this->getToken('Number'))) {
                $alt3 = 1;
            } else if (($LA3_0 == $this->getToken('10'))) {
                $alt3 = 2;
            } else {
                $nvae = new NoViableAltException("", 3, 0, $this->input);
                throw $nvae;
            }
            
            switch ($alt3) {
                case 1: {
                    $n     = $this->match($this->input, $this->getToken('Number'), self::$FOLLOW_Number_in_atomExp233);
                    $value = has($n) ? doubleval($n->getText()) : null;
                }
                    break;
                case 2: {
                    $this->match($this->input, $this->getToken('10'), self::$FOLLOW_10_in_atomExp261);
                    $this->pushFollow(self::$FOLLOW_additionExp_in_atomExp265);
                    $exp = $this->additionExp();
                    $this->state->_fsp--;
                    $this->match($this->input, $this->getToken('11'), self::$FOLLOW_11_in_atomExp267);
                    $value = $exp;
                }
                    break;
            }
        } catch (RecognitionException $re) {
            $this->reportError($re);
            $this->recover($this->input, $re);
        } catch (Exception $e) {
            throw $e;
        }
        
        return $value;
    }
}

ExpParser::$FOLLOW_additionExp_in_compute32      = new Set(array(
    1
));

ExpParser::$FOLLOW_multiplyExp_in_additionExp60  = new Set(array(
    1,
    6,
    7
));

ExpParser::$FOLLOW_6_in_additionExp82            = new Set(array(
    4,
    10
));

ExpParser::$FOLLOW_multiplyExp_in_additionExp86  = new Set(array(
    1,
    6,
    7
));

ExpParser::$FOLLOW_7_in_additionExp102           = new Set(array(
    4,
    10
));

ExpParser::$FOLLOW_multiplyExp_in_additionExp106 = new Set(array(
    1,
    6,
    7
));

ExpParser::$FOLLOW_atomExp_in_multiplyExp147     = new Set(array(
    1,
    8,
    9
));

ExpParser::$FOLLOW_8_in_multiplyExp168           = new Set(array(
    4,
    10
));

ExpParser::$FOLLOW_atomExp_in_multiplyExp172     = new Set(array(
    1,
    8,
    9
));
ExpParser::$FOLLOW_9_in_multiplyExp188           = new Set(array(
    4,
    10
));

ExpParser::$FOLLOW_atomExp_in_multiplyExp192     = new Set(array(
    1,
    8,
    9
));

ExpParser::$FOLLOW_Number_in_atomExp233          = new Set(array(
    1
));

ExpParser::$FOLLOW_10_in_atomExp261              = new Set(array(
    4,
    10
));

ExpParser::$FOLLOW_additionExp_in_atomExp265     = new Set(array(
    11
));

ExpParser::$FOLLOW_11_in_atomExp267              = new Set(array(
    1
));

/* Return true if $value is not empty() with the exception of 0 */ 
function has($value = null) {
    return !( empty($value) && '0' != $value );
} 
?>